#!/bin/bash

# This script should work on most linux distributions.
# If everything goes well, the HAR package "ohos-sha2.har" should be in project root directory.

# rust toolchains

rustup default stable
rustup update stable

rustup target add aarch64-unknown-linux-ohos
rustup target add x86_64-unknown-linux-ohos

# OpenHarmony SDK 

curl -LO https://repo.huaweicloud.com/harmonyos/os/5.1.0-Release/ohos-sdk-windows_linux-public.tar.gz
tar -xf ohos-sdk-windows_linux-public.tar.gz
pushd ohos-sdk/linux
for f in *.zip ; do
    unzip "$f" > /dev/null
    rm "$f"
done
popd
export OHOS_NDK_HOME="$PWD/ohos-sdk/linux"

# ohrs

cargo install ohrs --git https://github.com/ohos-rs/ohos-rs
ohrs="${CARGO_HOME:-$HOME/.cargo}/bin/ohrs"

# build

"$ohrs" build --release -a aarch -a x64

# package

"$ohrs" artifact -n ohos-sha2